package com.isky.visual.result;


import lombok.Data;

/**
 * @ClassName : CodeMsg
 * @Description : 返回给页面的code 码
 * @Author :wudl
 * @Date: 2020-04-12 14:45
 */
@Data
public class CodeMsg {
    private int code;
    private String msg;

    //通用的错误码
    public static CodeMsg SUCCESS = new CodeMsg(0, "success");
    public static CodeMsg LOGIN_ERROR = new CodeMsg(-105, "登录失败");
    public static CodeMsg SERVER_ERROR = new CodeMsg(500100, "服务端异常");
    public static CodeMsg BIND_ERROR = new CodeMsg(500101, "参数校验异常：%s");
    public static CodeMsg REQUEST_ILLEGAL = new CodeMsg(500102, "请求非法");
    public static CodeMsg ACCESS_LIMIT_REACHED = new CodeMsg(500104, "访问太频繁！");

    public static CodeMsg DB_UPDATE_SUCCESS = new CodeMsg(500105, "数据更新成功");
    public static CodeMsg DB_UPDATE_ERROR = new CodeMsg(500106, "数据更新失败");

    public static CodeMsg DB_DELETE_ERROR = new CodeMsg(500107, "数据删除失败");
    public static CodeMsg DB_DELETE_SUCCESS = new CodeMsg(500108, "数据删除成功");

    public static CodeMsg DB_ADDDATA_ERROR = new CodeMsg(500107, "数据添加失败");
    public static CodeMsg DB_ADDDATA_SUCCESS = new CodeMsg(500108, "数据添加成功");
    public static CodeMsg DATA_ERROR = new CodeMsg(500109, "内部异常");
    public static CodeMsg DATA_PARSE_ERROR = new CodeMsg(500110, "未获取到解析的数据");

    public static CodeMsg DB_GET_DATA_ERROR = new CodeMsg(500111, "获取表数据失败");

    public static CodeMsg QUERY_PARAMETER = new CodeMsg(500112, "参数不能为空");
    public static CodeMsg DB_DATA_SUCCESS = new CodeMsg(500113, "数据删除成功");
    public static CodeMsg DATA_FORMATTED_ERROR = new CodeMsg(500113, "数据格式错误");
    public static CodeMsg DATA_COPY_ERROR = new CodeMsg(500113, "数据复制失败");
    public static CodeMsg TABLE_COLUMN_ERROR = new CodeMsg(500113, "获取表字段失败");



    //登录模块 5002XX
    public static CodeMsg SESSION_ERROR = new CodeMsg(-105, "未登录或登录状态已经失效");
    public static CodeMsg PASSWORD_EMPTY = new CodeMsg(500211, "登录密码不能为空");
    public static CodeMsg MOBILE_EMPTY = new CodeMsg(500212, "手机号不能为空");
    public static CodeMsg MOBILE_ERROR = new CodeMsg(500213, "手机号格式错误");
    public static CodeMsg MOBILE_NOT_EXIST = new CodeMsg(500214, "手机号不存在");
    public static CodeMsg PASSWORD_ERROR = new CodeMsg(500215, "密码错误");
    public static CodeMsg USERNAME_NULL = new CodeMsg(500216, "用户名不存在");
    public static CodeMsg LOGIN_SUCCESS = new CodeMsg(500217, "用户登录成功");
    public static CodeMsg LOGIN_FAILD = new CodeMsg(500217, "用户登录失败");

    //数据库模块 5003XX
    public static CodeMsg DB_NOT_EXIST = new CodeMsg(500400, "数据库不存在");
    public static CodeMsg DB_CONNECTION_ERROR = new CodeMsg(500401, "测试连接不通过");
    public static CodeMsg DB_CONNECTIONS = new CodeMsg(500402, "数据库连接成功");
    public static CodeMsg DB_CONNECTION_NULL = new CodeMsg(500403, "数据库连接不能为空");
    public static CodeMsg DB_IP_NULL = new CodeMsg(500404, "数据库ip 地址不能为空");
    public static CodeMsg DB_USERNAME_NULL = new CodeMsg(500405, "数据库用户名不能为空");
    public static CodeMsg DB_PASSWORD_NULL = new CodeMsg(500406, "数据库密码不能为空");
    public static CodeMsg DB_TYPE_NULL = new CodeMsg(500407, "数据库数据库类型不能空");
    public static CodeMsg DB_PORT_NULL = new CodeMsg(500408, "数据库端口不能为空");
    public static CodeMsg DB_SOURCE_ID_NULL = new CodeMsg(500409, "数据源id 不能为空");
    public static CodeMsg DB_SAVE_SOURCE_SUCCESS = new CodeMsg(500409, "数据保存成功");
    public static CodeMsg DB_SAVE_SOURCE_ERROE = new CodeMsg(500409, "数据保存失败");
    public static CodeMsg DB_QUERY_ERROE = new CodeMsg(500409, "查询数据异常");
    public static CodeMsg DATASTORE_QUERY_ERROE = new CodeMsg(500410, "没有查询到数据集");
    public static CodeMsg DB_QUERY_ERROR = new CodeMsg(500411, "数据库查询异常");
    public static CodeMsg DB_SELECT_ILLEGAL = new CodeMsg(500412, "非法sql");
    public static CodeMsg DB_CONN_NAME_EXIT = new CodeMsg(500413, "该用户下已存在相同的数据库连接名！");
    public static CodeMsg DB_CONN_TYPE_UNKNOW = new CodeMsg(500414, "未知的数据库类型");

    public static CodeMsg FEIGN_REQUEST_ERROR = new CodeMsg(500415, "调用统一身份认证平台Feign请求异常！");
    public static CodeMsg DB_CONN_ON_CHANGE = new CodeMsg(500416, "目标数据库不可变更");




    //解析json 模块 5005XX

    public static CodeMsg MODE_JSON_FORMAT_ERROR = new CodeMsg(500500, "查询条件为空");
    public static CodeMsg MODE_JSON_FORMAT_JOIN_ERROR = new CodeMsg(500501, "数据源关联关系不存在或格式错误");


    //数据源模块 5006XX
    public static CodeMsg DATA_STORE_NULL = new CodeMsg(500600, "数据源不存在");


    //设计器模块 5007XX
    public static CodeMsg PROJECT_GROUP_EXISTS = new CodeMsg(500700, "组信息已存在");
    public static CodeMsg PROJECT_NUll = new CodeMsg(500700, "未查询到信息");

    private CodeMsg() {
    }

    private CodeMsg(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }


    public CodeMsg fillArgs(Object... args) {
        int code = this.code;
        String message = String.format(this.msg, args);
        return new CodeMsg(code, message);
    }

    public CodeMsg Clone() {
        return new CodeMsg(this.code, this.msg);
    }

    @Override
    public String toString() {
        return "CodeMsg [code=" + code + ", msg=" + msg + "]";
    }


}
